/*
 *  Created on: Nov 15, 2012
 *      Author: Andrey Belomutskiy
 */

#ifndef RFICONSOLE_H_
#define RFICONSOLE_H_

#include "main.h" // optional
#ifdef CHIBIOS
 #include <ch.h>
 #include <hal.h>
#else
 #include <stm32f4xx.h>
#endif
#include "rfiutil.h"

#ifndef CONSOLE_CHANNEL
#define CONSOLE_CHANNEL (&SD3)
#endif

#ifndef CONSOLE_TX_PORT
#define CONSOLE_TX_PORT GPIOB
#endif

#ifndef CONSOLE_RX_PORT
#define CONSOLE_RX_PORT GPIOB
#endif

#ifndef CONSOLE_TX_PIN
#define CONSOLE_TX_PIN 10
#endif

#ifndef CONSOLE_RX_PIN
#define CONSOLE_RX_PIN 11
#endif

#define CONSOLE_TX_AF 7
#define CONSOLE_RX_AF 7

#ifndef VERSION_STRING
#define VERSION_STRING "(NO VERSION)"
#endif

#define ERROR_CODE -11223344
#define CONSOLE_MAX_ACTIONS 32

typedef enum {
	NO_PARAMETER = 0, ONE_PARAMETER = 1,
} ACTION_PARAMETER_TYPE;

typedef struct {
	char *token;
	int parameterType;
	void (*callback)(void);
} TokenCallback;

void initConsole();
int atoi(char *string);
void print(const char *fmt, ...);
#ifdef CHIBIOS
 BaseChannel * getSdChannel();
#endif

void handleConsoleLine(char *line);
void addConsoleAction(char *token, void (*callback)(void));
void addConsoleAction1(char *token, void (*callback)(int));
void fatal(char *msg);

#endif /* RFICONSOLE_H_ */
